
$(function () {
    var isMulti = $.getQueryParam('isMulti');
    var singleSelect = true;
    if (isMulti && isMulti.toString() === '1') {
        singleSelect = false;
    }
    $('#factorTb').datagrid({
        rownumbers: true,//显示行号
        striped: true,
        fit: true,
        singleSelect: singleSelect,
        sortOrder: true,
        fitColumns: true,
        pagination: true,
        toolbar: '#toolbar',
        url: ROOT_PATH + '/occupationalHealth/hazardFactor/factorTable.shtml',
        queryParams:{
            sort:'addTime',
            order:'desc'
        },
        columns: [[
            {
                field: 'id',
                checkbox: true
            },
            {field: 'name', title: '危害因素名称', width: 100},
            {field: 'harmName', title: '危害因素类型', width: 100},
            {field: 'uint', title: '计量单位', width: 100},
            {field: 'mac', title: 'MAC', width: 100},
            {field: 'pcstel', title: 'PC-STEL', width: 100},
            {field: 'pctwa', title: 'PC-TWA', width: 100},
            {field: 'testDate', title: '检测周期（次/年）', width: 150}
        ]]
    });
    queryComboData();
    $('#btn_clear').on("click", function () {
        $('#queryForm').form('reset');
    });
    $('#btn_save').on("click", function () {
        var $selected = $('#factorTb').datagrid('getSelections');
        if ($selected.length === 0) {
            layer.alert("请选择一条数据！");
            return;
        }
        WindowManager.closeLayer({
            returnValue: $selected
        });
    });
});

function queryComboData() {
    var code=CONSTANT.DictionaryTypeDefConstants.OHE_HARM_TYPE;
    var EMPTY_OPTION = {
        id: '',
        text: '请选择'
    };
    $.ajax({
        type: 'post',
        url: ROOT_PATH + '/permission/dictionary/queryDictionaryByDictionaryTypeCode.shtml',
        data: {code: code},
        dataType: "json",
        success: function (result) {
            $('#harmIdQuery').combobox({
                loadFilter: function (data) {
                    data.unshift(EMPTY_OPTION);
                    return data;
                },
                data: result,
                valueField: 'id',
                textField: 'text',
                editable: false,
                panelHeight: '200',
                onSelect: function (record) {
                }
            });
        }
    });
}
/**
 * 重新加载表格
 */
function reLoadData() {
    $('#factorTb').datagrid('clearSelections');
    var queryParams = $('#queryForm').serializeJson();
    queryParams["sort"] = 'addTime';
    queryParams["order"] = 'desc';
    $('#factorTb').datagrid('options').queryParams = queryParams;
    $("#factorTb").datagrid('reload', ROOT_PATH + '/occupationalHealth/hazardFactor/factorTable.shtml');
}
